package com.network.topo.snmp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.snmp4j.Target;

import com.network.util.snmp4j.SnmpGet;
import com.network.util.snmp4j.SnmpGetResultSet;

public class Dot1dStpPortTable extends AbstractXxxTable
{
	private static ArrayList<String> oidList = null;
	private HashMap<Object, RowData> objDataMap = new HashMap<Object, RowData>();
	private HashMap<Object, RowData> indexDataMap = new HashMap<Object, RowData>();
	private int rowCount = 0;

	private Dot1dStpPortTable(SnmpGetResultSet resultSet)
	{
		this.resultSet = resultSet;
		if (this.resultSet != null)
		{
			rowCount = this.resultSet.getRowCount();
			for (int i = 0; i < rowCount; i++)
			{
				RowData rowData = new RowData();
				int oidIndex = 0;
				rowData.dot1dStpPort = getValue(getOidList().get(oidIndex++), i);
				rowData.dot1dStpPortState = getValue(getOidList().get(oidIndex++), i);
				rowData.dot1dStpPortDesignatedRoot = getValue(getOidList().get(oidIndex++), i);
				rowData.dot1dStpPortDesignatedBridge = getValue(getOidList().get(oidIndex++), i);
				rowData.dot1dStpPortDesignatedPort = getValue(getOidList().get(oidIndex++), i);
				
				indexDataMap.put(i, rowData);
			}
		}
	}

	public static Dot1dStpPortTable getInstance(SnmpGet snmpGet, Target target,List<String> commList)
	{
		SnmpGetResultSet sgrs = null;
		Dot1dStpPortTable instance = null;
		try
		{
			sgrs = snmpGet.query(getOidList(), target,commList);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		if (sgrs != null && sgrs.next() == true)
		{
			instance = new Dot1dStpPortTable(sgrs);
		}
		return instance;
	}

	public static synchronized ArrayList<String> getOidList()
	{
		if (oidList == null)
		{
			oidList = new ArrayList<String>();
			oidList.add("1.3.6.1.2.1.17.2.15.1.1");
			oidList.add("1.3.6.1.2.1.17.2.15.1.3");
			oidList.add("1.3.6.1.2.1.17.2.15.1.6");
			oidList.add("1.3.6.1.2.1.17.2.15.1.8");
			oidList.add("1.3.6.1.2.1.17.2.15.1.9");
		}
		return oidList;
	}
	
	
	public class RowData
	{
		private String dot1dStpPort = "";
		private String dot1dStpPortState = "";
		private String dot1dStpPortDesignatedRoot = "";
		private String dot1dStpPortDesignatedBridge = "";
		private String dot1dStpPortDesignatedPort = "";
		
		public String getDot1dStpPortDesignatedBridge() {
			return dot1dStpPortDesignatedBridge;
		}

		public void setDot1dStpPortDesignatedBridge(String dot1dStpPortDesignatedBridge) {
			this.dot1dStpPortDesignatedBridge = dot1dStpPortDesignatedBridge;
		}

		public String getDot1dStpPortDesignatedPort() {
			return dot1dStpPortDesignatedPort;
		}

		public void setDot1dStpPortDesignatedPort(String dot1dStpPortDesignatedPort) {
			this.dot1dStpPortDesignatedPort = dot1dStpPortDesignatedPort;
		}

		public String getDot1dStpPortDesignatedRoot() {
			return dot1dStpPortDesignatedRoot;
		}

		public void setDot1dStpPortDesignatedRoot(String dot1dStpPortDesignatedRoot) {
			this.dot1dStpPortDesignatedRoot = dot1dStpPortDesignatedRoot;
		}

		public String getDot1dStpPortState() {
			return dot1dStpPortState;
		}

		public void setDot1dStpPortState(String dot1dStpPortState) {
			this.dot1dStpPortState = dot1dStpPortState;
		}

		public String getDot1dStpPort()
		{
			return dot1dStpPort;
		}

		public void setDot1dBasePort(String dot1dBasePort)
		{
			this.dot1dStpPort = dot1dBasePort;
		}
	}

	public String getDot1dStpPort(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getDot1dStpPort();
		}
		return rtnValue;
	}

	public String getDot1dStpPortState(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getDot1dStpPortState();
		}
		return rtnValue;
	}
	
	public String getDot1dStpPortDesignatedBridge(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getDot1dStpPortDesignatedBridge();
		}
		return rtnValue;
	}

	public String getDot1dStpPortDesignatedPort(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getDot1dStpPortDesignatedPort();
		}
		return rtnValue;
	}
	
	public String getDot1dStpPortDesignatedRoot(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getDot1dStpPortDesignatedRoot();
		}
		return rtnValue;
	}
}
